﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;

public partial class DatHangNCC : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ngayBDCAL.SelectedDate = DateTime.Now;
        ngayKTCAL.SelectedDate = DateTime.Now.AddDays(90);
    }
    protected void datHangBTN_Click(object sender, EventArgs e)
    {
        GiaoDich gd = new GiaoDich();
        gd.MaSanPham = int.Parse(maSPTEXT.Text);
        gd.SlCapNhat = 100;
        gd.SlTonDeCapNhat = int.Parse(SLToiThieuTEXT.Text);
        gd.NgayBD = ngayBDCAL.SelectedDate;
        gd.NgayKT = ngayKTCAL.SelectedDate;

        List<GiaoDich> gds = new List<GiaoDich>();
        gds.Add(gd);
        try
        {
            System.Web.Services.Protocols.SoapHttpClientProtocol proxy = Session["MyServiceNCC"] as System.Web.Services.Protocols.SoapHttpClientProtocol;
            if (proxy == null)
            {
                proxy = (System.Web.Services.Protocols.SoapHttpClientProtocol)WSProxy.CreateWebService(WebServices_Param.WsNCCURL, WebServices_Param.WsNCCName);
                proxy.CookieContainer = new CookieContainer();
                Session["MyServiceNCC"] = proxy;
            }

            string sid = WSProxy.CallWebService(proxy, "dangNhap", new object[] { "NhaBanLeEM03", "NhaBanLeEM03" }).ToString();

            object kq = WSProxy.CallWebService(proxy, "datHang", new object[] { sid, gd.MaSanPham, gd.SlTonDeCapNhat, gd.SlCapNhat, gd.NgayBD, gd.NgayKT, "NhaBanLeEM03"});
            int maGD = WebServiceInvoker.ConvertType<int>(kq);

            if (maGD != -1)
            {
                Response.Write("<script>alert('Đặt hàng thành công! Mã giao dịch: "+maGD+"')</script>");
            }
            else
            {
                Response.Write("<script>alert('Đặt hàng CHƯA thành công!')</script>");
            }
        }
        catch (Exception ex) { } 
    }
}